//
//  ACFileInfoViewController.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/4/19.
//

#import "ACFileInfoViewController.h"
#import "ACLiveModel.h"
#import "ACFileInfoTableViewCell.h"

@interface ACFileInfoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)ACFileModel *fileModel;
@end

@implementation ACFileInfoViewController
-(UITableView *)tableview{
    if (!_tableview) {
        _tableview = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.estimatedRowHeight = ACSCREEN_HEIGHT - ACSafeAreaBottomHeight - ACStatusBarHeight - 44 ;
        _tableview.backgroundColor = UIColorFromRGB(0xF4F5F8);
        NSBundle *curB = [NSBundle BundleWithBundleName:ACLiteAVUISDK targetClass:[self class] ];
        [_tableview registerNib:[UINib nibWithNibName:@"ACFileInfoTableViewCell" bundle:curB] forCellReuseIdentifier:@"ACFileInfoTableViewCell"];
        _tableview.tableFooterView = [UIView new];
    }
    return _tableview;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.bottom.mas_equalTo(0);
    }];
}

-(void)setId_file:(NSString *)id_file{
    _id_file = id_file;
    [self requestData];
}

-(void)requestData{
    [SVProgressHUD show];
    [ACLiveRoomManager requestFileInfoWithFileID:self.id_file success:^(id  _Nonnull responseObject) {
        [SVProgressHUD dismiss];
        self.fileModel = [ACFileModel mj_objectWithKeyValues:responseObject];
        self.title = self.fileModel.title;
        [self.tableview reloadData];
    } failure:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.fileModel.file_page integerValue];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ACFileInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ACFileInfoTableViewCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[ACFileInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ACFileInfoTableViewCell"];
    }
    [cell setupFileInfoWithUrl:self.fileModel.thumbnail_url page:indexPath.row + 1];
    return cell;
}

@end
